#include <iostream>
#include <unordered_map>
using namespace std;
const int N = 1e5 + 10;
struct node
{
	int d;
	string v;
}a[N];
int main()
{
	int n, m;cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i].d >> a[i].v;
	}
	int ret = 0;
	for(int i = 1; i <= m; i++)
	{
		int k, c; cin >> k >> c;
		if(k == 0)
		{
			ret += c;
			ret %= n;	
		} 
		else
		{
			ret -= c;
			ret = (ret % n + n) % n;
		}
	}
	cout << a[ret].v << endl;
	return 0;
}
